/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "StdAfx.h"
#include ".\phantomtabctrlwindow.h"

CPhantomTabCtrlWindow::CPhantomTabCtrlWindow(void) : CPhantomWindow(String("SysTabControl32"))
{
}

CPhantomTabCtrlWindow::~CPhantomTabCtrlWindow(void)
{
}

int CPhantomTabCtrlWindow::FunctionProcessor(SSI_FunctionAPI& theAPI)
{
	if(theAPI.m_FunctionName == "SelectTab"){
		SSI_INT64 i = SSI_EXTRACT(CDataInt, 0);
		SendMessage(MyWin, TCM_SETCURFOCUS, i, 0);
		theAPI.m_ReturnStatus = STAT_OK;
	}else if(theAPI.m_FunctionName == "GetCount"){
		CDataInt i;
		CTabCtrl* Tab = (CTabCtrl*)aWnd;
		i.Data = Tab->GetItemCount();
		theAPI.m_ReturnStatus = theAPI.SetReturnData(&i);
	}else if(theAPI.m_FunctionName == "GetActiveTab"){
		CDataInt i;
		CTabCtrl* Tab = (CTabCtrl*)aWnd;
    i.Data = Tab->GetCurSel();
		theAPI.m_ReturnStatus = theAPI.SetReturnData(&i);
	}else if(theAPI.m_FunctionName == "GetTabText"){
		CDataString a;
		SSI_INT64 i = SSI_EXTRACT(CDataInt, 0);
		
		TCHAR szName[MINION_MAX_TEXT] = "";
		LPTCITEM pItem = new TCITEM;
	
		pItem->pszText = szName;
		pItem->cchTextMax = MINION_MAX_TEXT;
		pItem->mask = TCIF_TEXT;
		if(!TabCtrl_GetItem(MyWin, i, pItem)){
			P_MAKEERR1(ERR_P01550, i);
			delete pItem;
		}
		a.Data = szName;
		theAPI.SetReturnData(&a);
		theAPI.m_ReturnStatus = STAT_OK;
		delete pItem;
	}else{
		return CPhantomWindow::FunctionProcessor(theAPI);
	}
	return 1;
}

CPhantomWindow* CPhantomTabCtrlWindow::MakeWindow(void)
{
	return new CPhantomTabCtrlWindow();
}
